package per.ethan.springboot.example.config;

import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import per.ethan.springboot.example.realm.UserRealm;

/**
 * @author Ethan
 * @date 2020/06/17 11:24
 * Subject 用户
 * SecurityManager 管理所有用户
 * Realm 连接数据
 */
@Configuration
public class ShiroConfig {

    @Bean
    public UserRealm userRealm() {
        return new UserRealm();
    }

    @Bean
    public DefaultWebSecurityManager securityManager() {
        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
        manager.setRealm(userRealm());
        return manager;
    }

    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
        DefaultShiroFilterChainDefinition definition = new DefaultShiroFilterChainDefinition();
        definition.addPathDefinition("/login.html", "anon");
        definition.addPathDefinition("/user/login", "anon");
//        definition.addPathDefinition("/user/*", "perms[user:id]");
        definition.addPathDefinition("/**", "authc");
        return definition;
    }

}
